package cn.lg.soar.system.feign;

import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.system.api.constant.Const;
import cn.lg.soar.system.api.enums.AccessModeEnum;
import cn.lg.soar.system.api.model.BizFileDTO;
import cn.lg.soar.system.api.model.FastUploadVO;
import cn.lg.soar.system.api.model.FileVO;
import cn.lg.soar.system.api.service.IFileApi;
import cn.lg.soar.system.feign.fallback.FileApiFallbackFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 文件上传接口
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.system.biz.modules.general.client.FileApiClient")
@ApiClient
@FeignClient(
        name= Const.MODULE_NAME,
        path= Const.CLIENT_PATH + "/file",
        fallbackFactory= FileApiFallbackFactory.class,
        contextId="FileApiFeign"
)
public interface FileApiFeign extends IFileApi {

    @PostMapping("fastUpload")
    @Override
    FileVO fastUpload(FastUploadVO vo);

    @PostMapping("upload-dir")
    @Override
    FileVO upload(
            @RequestPart("file") MultipartFile file,
            @RequestParam("directory") String directory,
            @RequestParam("accessMode") AccessModeEnum accessMode
    );

    @PostMapping("upload")
    @Override
    FileVO upload(@RequestPart("file") MultipartFile file, @RequestParam("accessMode") AccessModeEnum accessMode);

    @PostMapping("saveBizFile")
    @Override
    boolean saveBizFile(@RequestParam("bizId") Long bizId, @RequestBody Collection<BizFileDTO> bizFiles);

    @GetMapping("getBizFile")
    @Override
    Map<String, List<FileVO>> getBizFile(@RequestParam("bizId") Long bizId, @RequestParam("bizTypes") Collection<String> bizTypes);

    @PostMapping("removeBizFile")
    @Override
    boolean removeBizFile(@RequestParam("bizId") Long bizId, @RequestParam("bizTypes") Collection<String> bizTypes);

}
